﻿using _111.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MyDapperApi.Models;
using MyDapperApi.Services;
using QYWXUpdate.DataModel;

namespace MyDapperApi.Controllers;

[ApiController]
[Route("api/[controller]")]
public class NetUpdateController : ControllerBase
{
    private readonly INetUpdateService _netUpdateService;

    public NetUpdateController(INetUpdateService netUpdateService)
    {
        _netUpdateService = netUpdateService;
    }

    [HttpGet("GetAll")]
    public async Task<IActionResult> GetAll()
    {
        var users = await _netUpdateService.GetAccessTokenAsync("ww41ce2a97523f4d1a", "gm0eUp5pNnuafpyRP8DsPNzuDJJx3J5omO53ervov2E");
        return Ok(users);
    }

    [HttpGet("Test")]
    [Authorize]
    public async Task<IActionResult> TestCtl()
    {
        var result = new CommonResponse();
        var userName = User.Identity.Name;
        var user1 = "测试接口连接成功"+ userName;
        result.SetSuccess(user1);
        
        return Ok(result);
    }

    [HttpGet("TestCode")]
    public async Task<IActionResult> TestCode([FromQuery] IdRequest request)
    {
        var result = new CommonResponse();
        var user1 = request.Id;
        result.SetSuccess(user1);

        return Ok(result);
    }

    [HttpGet("Get114514")]
    public async Task<IActionResult> Get114514()
    {
        var user1 = await _netUpdateService.UpdateKeyData();
        return Ok(user1);
    }

    [HttpPost("PostDetail")]
    public async Task<IActionResult> PostDetail([FromBody] QywxTotalModel request)
    {
        var user1 = await _netUpdateService.UpdateQywx(request);
        return Ok(user1);
    }

    [HttpGet("GetDetail")]
    public async Task<IActionResult> GetDetail([FromQuery] IdRequest request)
    {
        var user1 = await _netUpdateService.GetDetail(request);
        return Ok(user1);
    }

    [HttpGet("GetUserDetail")]
    public async Task<IActionResult> GetUserDetail()
    {
        var user1 = await _netUpdateService.GetUserIdByCorpToken();
        return Ok(user1);
    }

    [HttpPost("PostTest")]
    public async Task<IActionResult> PostTest()
    {
        var user1 = await _netUpdateService.UpdateReport();
        return Ok(user1);
    }
}